package ud13.ventanas6;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Main extends JFrame {
	int tAncho;
	int tAlto;
	private JPanel p;
	private JPanel p1;
	
	private void inicializar() {
		int anchoPantalla=Toolkit.getDefaultToolkit().getScreenSize().width;
		int altoPantalla=Toolkit.getDefaultToolkit().getScreenSize().height;
		tAncho=200;
		tAlto=200;
		setSize(tAncho, tAlto);
		setLocation(anchoPantalla/2-tAncho/2, altoPantalla/2-tAlto/2);
		setTitle("Ejercicio 04");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		p = new JPanel();
		this.add(p);
		p1 = new JPanel();
		this.add(p1);
	}
	
	private void esperar() {
		for (int i = 0; i<100000; i++) {
			for (@SuppressWarnings("unused")
			int j=0; i<10000000; i++) {
				
			}
		}
	}
	
	private void banderaEspanya() {
		p.setLayout(new GridLayout(3,1));
		
		JPanel p1 = new JPanel();
		p1.setBackground(Color.RED);
		p.add(p1);
		
		JPanel p2 = new JPanel();
		p2.setBackground(Color.YELLOW);
		p.add(p2);
	
		JPanel p3 = new JPanel();
		p3.setBackground(Color.RED);
		p.add(p3);
		
		pack();
	}
	
	private void banderaItalia() {
		p1.setLayout(new GridLayout(1,3));
		
		JPanel p2 = new JPanel();
		p2.setBackground(Color.GREEN);
		p1.add(p2);
		
		JPanel p3 = new JPanel();
		p3.setBackground(Color.WHITE);
		p1.add(p3);
	
		JPanel p4 = new JPanel();
		p4.setBackground(Color.RED);
		p1.add(p4);
		
		pack();
	}
	
	public Main() {
		inicializar();
		banderaItalia();
	}
	
	@SuppressWarnings("unused")
	private void mover() {
		int x = this.getLocation().x;
		int y = this.getLocation().y;
		
		for (int i = 0; i<200; i++) {
			setLocation(x+i, y);
			setSize(100+i, 400);
			esperar();
		}
	}

	public static void main(String[] args) {
		new Main();
	}
	
	@SuppressWarnings("unused")
	private static String getTitulo() {
		String sol="";
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		System.out.println("Dime un titulo para tu ventana: ");
		sol=scan.nextLine();
		return sol;
	}
}
